﻿//模块描述：    系统日志列表页
//创建人：      wang
//创建日期：    2010年05月20日
//修改描述：
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Drawing;
using webnew.Common;
namespace webnew.Systems
{
    public partial class S_LogList : ListBase
    {   
        protected void Page_Load(object sender, EventArgs e)
        {

            //_ListTbName = "Sys_Log";       //执行删除语句的数据库表名
            _EditSrc = "S_LogEdit.aspx";  //编辑页路径
            //_DelType = DeleteType.FalseDel;//逻辑删除
            _Grdview = grdView;//主列表控件                  
            btnExcelVisble = false; //设置导出不可见     
           
            
            if (!IsPostBack)
            {
                Common.CommonHelper.DataDdlBind(ddlModule, new BLL.Sys_Navigation().GetModule(), "NaviName", "NaviName");
                ddlModule.Items.Insert(0, new ListItem("全部", ""));
                ddlModule.Items.Insert(1, new ListItem("登录日志", "登录日志"));
                SetTitle(true, "后台管理 >> 系统日志");
                AspNetPager1_PageChanged(null, null);
            }
        }

        /// <summary>
        /// 重写删除事件,使删除后刷新页面;
        /// </summary>
        protected override void _Del()
        {
            base._Del();
            AspNetPager1_PageChanged(null, null);
        }




        /// <summary>
        /// 检索按钮事件
        /// </summary>
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            AspNetPager1_PageChanged(null, null);

        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {

            //string beginTime = "1987-1-1";
            //string endTime = "2080-1-1";
            //if (txtBeginTime.Text.Trim() == "") beginTime = "1987-1-1";
            //else beginTime = txtBeginTime.Text;

            //if (txtEndTime.Text.Trim() == "") endTime = "2080-1-1";
            //else endTime = txtEndTime.Text;
            string beginTime = MyConvert.toMinDateTime(txtBeginTime.Text).ToString();
            string endTime = MyConvert.toMaxDateTime(txtEndTime.Text).ToString();
            //分页的查询表名
            System.Text.StringBuilder _tableName = new System.Text.StringBuilder();
            //分页的查询字段
            System.Text.StringBuilder _field = new System.Text.StringBuilder();

            _field.Append(" a.*,b.trueName,b.loginID");

            _tableName.Append(" Sys_Log a join Sys_User b on a.UserID = b.Id  ");

            //分页的查询的条件
            System.Text.StringBuilder _conditon = new System.Text.StringBuilder();
            _conditon.Append("  a.createDate between '" + beginTime + "' and '" + endTime + "' ");
            if (ddlModule.SelectedValue != "")
            {
                //除登录日志之外的模块
                if (!(ddlModule.SelectedValue == "登录日志"))
                    _conditon.Append(" and b.isdel=0 and a.module like '%" + ddlModule.SelectedValue + "%'");
               //登录日志
                else
                     _conditon.Append(" and b.isdel=0 and  a.module='' ");
            }
            if (ddlStatus.SelectedValue != "全部") _conditon.Append(" and a.status= '" + ddlStatus.SelectedValue + "'");

            AspNetPager1.RecordCount = new BLL.Sys_Log().GetCount(_tableName.ToString(), _conditon.ToString());
            webnew.Common.CommonHelper.DataGrdBind(grdView, new BLL.Sys_Log().GetPageList(_field.ToString(), _conditon.ToString(), grdView.PageSize, AspNetPager1.CurrentPageIndex, _tableName.ToString(), "a.createDate",false));
        }

        protected void grdView_DataBound(object sender, EventArgs e)
        {
            for (int i = 0; i < grdView.Rows.Count; i++)
            {
                
                //grdView.Rows[i].Cells[1].Text =Common.MyConvert.toString(i+1);
                grdView.Rows[i].Cells[2].Text = new BLL.Sys_Log().GetTrueName(grdView.Rows[i].Cells[2].Text);
                grdView.Rows[i].Cells[3].Text = new BLL.Sys_Log().GetLoginID(grdView.Rows[i].Cells[3].Text);
                 if (grdView.Rows[i].Cells[6].Text=="出错") 
                {
                    grdView.Rows[i].ForeColor = Color.Red;
                }
                 //grdView.Rows[i].Cells[8].ToolTip = grdView.Rows[i].Cells[8].Text;
                 //if (grdView.Rows[i].Cells[8].Text.Length > 42)
                 //{
                     
                 //    grdView.Rows[i].Cells[8].Text = grdView.Rows[i].Cells[8].Text.Substring(0,42) + "...";
                 //}
            }
          
        }

        protected void grdView_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            //鼠标经过变色
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "GridViewMouseover(this)");
                e.Row.Attributes.Add("onmouseout", "GridViewMouseout(this)");
                e.Row.Attributes.Add("onclick", "GridViewonclick(this)");
            }
            webnew.Common.CommonHelper.grdCellStyle(e.Row.Cells[4], 14);
            webnew.Common.CommonHelper.grdCellStyle(e.Row.Cells[5], 8);
            webnew.Common.CommonHelper.grdCellStyle(e.Row.Cells[8], 42);
            webnew.Common.CommonHelper.grdCellStyle(e.Row.Cells[9], 18);
        }

        /// <summary>
        /// 显示条数下拉框
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ddlPageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            grdView.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
            AspNetPager1.PageSize = Convert.ToInt32(ddlPageSize.SelectedValue);
            AspNetPager1_PageChanged(null, null);
        }


    }
}
